<?php
require('../include/init.inc.php');
$method = $id = $products_id = $products_name = $products_img = $products_desc_images = $products_sales_num = $remaining_time = $products_price = $products_special_price = $products_currency = $products_desc = '';
extract($_REQUEST, EXTR_IF_EXISTS);


$product = AdminProducts::getProductById($id);

if (Common::isPost()) {
    if (strlen($products_name) > 26) {
        $products_name = substr($products_name, 0, 26);
    }

    if (strlen($products_desc) > 120) {
        $products_desc = substr($products_desc, 0, 120);
    }

    $product = AdminProducts::getProductById($products_id);

    if (!$product) {
        Common::exitWithError(ErrorMessage::PRODUCT_NOT_EXIST, "snap/products.php");
    }

    $data = array('products_id' => $products_id, "products_name" => $products_name, "products_img" => $products_img, "products_desc_images" => $products_desc_images, "products_sales_num" => $products_sales_num, "remaining_time" => $remaining_time, "products_price" => $products_price, "products_special_price" => $products_special_price, "products_currency" => $products_currency, "products_desc" => $products_desc);

    $where = array('products_id' => $products_id);
    $ret = AdminProducts::update($where, $data);
    if ($ret) {
        SysLog::addLog(UserSession::getUserName(), 'Update', 'ProductsUpdate', $id, json_encode($data));
        Common::exitWithSuccess('更新完成', 'snap/products.php');
    } else {
        OSAdmin::alert("error");
    }
}


$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign('osadmin_action_confirm', $confirm_html);
Template::assign('_POST', $product);
Template::display('snap/products_modify.tpl');